package enums;

/**
 * Created by jianweilin on 16/8/21.
 */
public class EnumDemo {
    public static void main(String[] args) {

        for (RainbowEnum colorEnum : RainbowEnum.values()) {
            System.out.println("code = " + colorEnum.getCode());
            System.out.println("desc = " + colorEnum.getDesc());
        }
        RainbowEnum color = RainbowEnum.valueOf("RED"); //非red,故valueOf("枚举名称")
        System.out.println("code = " + color.getCode());
        System.out.println("desc = " + color.getDesc());
        System.out.println("name = " + color.name());
    }

    public static void define() {
        RainbowEnum color = RainbowEnum.GREEN;
        switch (color) {
            case GREEN:
                System.out.println("this is GREEN");
                break;
            case CYAN:
                System.out.println("this is CYAN");
                break;
            case BLUE:
                System.out.println("this is BLUE");
                break;
            default:
                System.out.println("other color");
        }
    }
}
